#ifndef __PARSER_H
#define __PARSER_H

#include "scanner.h"
#include "symtable.h"
#include "Vector3.h"
#include "SceneNode.h"

#include "NewB2OEvent.h"
#include "EventSystem.h"
#include "TranslateEvent.h"


using namespace xEngine::CoreSystem::Events;
using namespace xEngine::PlatformIndependent;
using namespace xEngine::PlatformIndependent::Math;



enum TRANSFORMATION
{
    ROTATE, TRANSLATE
};


enum OP
{
    ADD, SUB, MUL, DIV
};



struct TransformationData {
    TRANSFORMATION metaData;
    void *data;

    // Constructor
    TransformationData() : data(NULL) {
        // ...
    }

    // Destructor
    ~TransformationData() {
        if (data != NULL)
            delete data;
    }
};

class Parser {
public:

    Parser();

    bool parse(string line);

    void compileFile(char *file, SymTable<SceneNode*> *objMap);
    void compileString(string str);

    string getStatus();

    void shutDown();


private:
	Scanner *scanner; // skener
	SymTable<float> symTab; // Symbol table
	string g_Error; // Error log

      //  map<string,  xEngine::PlatformIndependent::SceneNode*> *currentObjectsTab;

        SymTable<SceneNode*> *objectsTab;

	bool XSCRIPT();
	bool BODY();
	bool B();
	bool LINE();

	bool DEFVAR();
	bool UPDATEVAR();

	/*
    OBJ_TYPE ::= static | dynamic

    OBJ_PROPERTIES ::= MATERIAL | SHAPE | VISUAL

    MATERIAL ::= material(DENSITY RESTITUTION) | material( set material_id ) |  ݓԊ    DENSITY ::= density:E |  ݓԊ    RESTITUTION ::= restitution:E |  ݓԊ
    SHAPE ::= rectangle = (width:E height:E) | circle = radius:E | vertices = { VERTICES_LIST } |  ݓԊ
    VISUAL ::= color (BORDER FILL) | texture ( filename ) |  ݓԊ    BORDER ::= border:COLOR4 |  ݓԊ    FILL ::= fill:COLOR4 |  ݓԊ    COLOR4 ::= [E E E E]
    */
	bool DEFOBJ();
	bool OBJ_TYPE(TYPE &objType);
        
	bool OBJ_PROPERTIES( MaterialData &materialData, ShapeData &shapeData, VisualData &visualData, 
        xEngine::CoreSystem::Events::SHAPE &shapeType, xEngine::CoreSystem::Events::VISUAL &visualType );

	bool MATERIAL(MaterialData &materialData);
	bool DENSITY(float &val);
	bool RESTITUTION(float &val);
	bool SHAPE(ShapeData &shapeData, xEngine::CoreSystem::Events::SHAPE &shapeType);
	bool VISUAL(VisualData &visualData, xEngine::CoreSystem::Events::VISUAL &visualType);
        bool TEX_REPEAT(float &rX, float &rY);
	bool BORDER(Color4 &color4);
	bool FILL(Color4 &color4);
	bool COLOR4(Color4 &color4);

        bool APPLY_FORCE();
        bool APPLY_LINEAR_VELOCITY();

	bool TRANSFORMATION(TransformationData *&tData);
	bool OBJECT(string &object);
	bool VECTOR(Vector3 *&vec);
	bool E(float &val);
	bool EE(float &val, float inVal);
	bool T(float &val);
	bool TT(float &val, float inVal);
	bool OP_1(OP &op);
	bool OP_2(OP &op);
	bool FUNC(float &val);
	bool F(float &val);
};

#endif
